package org.example.demo3.vo;
import lombok.Data;
import static org.example.demo3.enums.StatusCodeEnum.SUCCESS;
import static org.example.demo3.enums.StatusCodeEnum.FAIL;
@Data
public class result<T> {
    private Integer code;

    private T data;

    private String msg;

    public static <T> result<T> success(T data) {
        return build(data, SUCCESS.getCode(), SUCCESS.getMsg());
    }

    public static <T> result<T> success() {
        return build(null, SUCCESS.getCode(), SUCCESS.getMsg());
    }

    public static <T> result<T> fail(String message) {
        return build(null, FAIL.getCode(), message);
    }

    private static <T> result<T> build(T data, Integer code, String message) {
        result<T> r = new result<T>();
        r.setData(data);
        r.setCode(code);
        r.setMsg(message);
        return r;
    }


}
